import Router from 'koa-router';
import checkPermission from '../middleware/permissionMiddleware';
import { addressController } from '../controllers/address.controller';

const router = new Router();

router.get('/addresses', checkPermission('view_address'), addressController.query);
router.post('/addresses', checkPermission('create_address'), addressController.insert);
router.put('/addresses/:id', checkPermission('update_address'), addressController.update);
router.delete('/addresses/:id', checkPermission('delete_address'), addressController.remove);
router.get('/addresses/:id', checkPermission('view_address'), addressController.queryById);

/**
 * @swagger
 * tags:
 *   name: Address
 *   description: 地址相关操作
 */

/**
 * @swagger
 * /addresses:
 *   get:
 *     summary: 获取地址列表
 *     tags: [Address]
 *     parameters:
 *       - $ref: '#/components/parameters/PageParam'
 *       - $ref: '#/components/parameters/SizeParam'
 *       - $ref: '#/components/parameters/UserIdParam'
 *     responses:
 *       200:
 *         description: 成功返回地址列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "成功"
 *                 data:
 *                   type: object
 *                   properties:
 *                     list:
 *                       type: array
 *                       items:
 *                         $ref: '#/components/schemas/AddressListDto'
 *                     total:
 *                       type: integer
 *                       example: 10
 *       401:
 *         description: 用户未授权访问
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 401
 *                 message:
 *                   type: string
 *                   example: "未授权"
 *       404:
 *         description: 地址未找到
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 404
 *                 message:
 *                   type: string
 *                   example: "地址未找到"
 *       500:
 *         description: 服务器内部错误
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 500
 *                 message:
 *                   type: string
 *                   example: "服务器内部错误"
 */

/**
 * @swagger
 * /addresses:
 *   post:
 *     summary: 创建新地址
 *     tags: [Address]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: '#/components/schemas/AddressCreateDto'
 *     responses:
 *       201:
 *         description: 地址创建成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "成功"
 *                 data:
 *                   type: boolean
 *                   example: true
 *       401:
 *         description: 用户未授权访问
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 401
 *                 message:
 *                   type: string
 *                   example: "未授权"
 */

/**
 * @swagger
 * /addresses/{id}:
 *   put:
 *     summary: 更新地址信息
 *     tags: [Address]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         description: 地址ID
 *         schema:
 *           type: integer
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: '#/components/schemas/AddressUpdateDto'
 *     responses:
 *       200:
 *         description: 更新成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "成功"
 *                 data:
 *                   type: boolean
 *                   example: true
 *       404:
 *         description: 地址未找到
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 404
 *                 message:
 *                   type: string
 *                   example: "地址未找到"
 *       401:
 *         description: 未授权
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 401
 *                 message:
 *                   type: string
 *                   example: "未授权"
 */

/**
 * @swagger
 * /addresses/{id}:
 *   delete:
 *     summary: 删除地址
 *     tags: [Address]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         description: 地址ID
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 删除成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "成功"
 *                 data:
 *                   type: boolean
 *                   example: true
 *       404:
 *         description: 地址未找到
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 404
 *                 message:
 *                   type: string
 *                   example: "地址未找到"
 *       401:
 *         description: 未授权
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 401
 *                 message:
 *                   type: string
 *                   example: "未授权"
 */

/**
 * @swagger
 * /addresses/{id}:
 *   get:
 *     summary: 获取单个地址信息
 *     tags: [Address]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         description: 地址ID
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 返回地址信息
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "成功"
 *                 data:
 *                   type: object
 *                   $ref: '#/components/schemas/AddressSingleDto'
 *       404:
 *         description: 地址未找到
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 404
 *                 message:
 *                   type: string
 *                   example: "地址未找到"
 *       401:
 *         description: 未授权
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 401
 *                 message:
 *                   type: string
 *                   example: "未授权"
 */

export default router;
